import { createApp,nextTick,h,render } from 'vue'
import bulletinDialog from '@/views/common/bulletin.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
let mountNode
let bulletinDialogModel = {}
let app 
bulletinDialogModel.install = (option = {})=>{
  if (mountNode && !option.doubleDialog) {//确保只存在一个弹窗
    app.unmount(mountNode); 
    document.body.removeChild(mountNode)
    mountNode = null
  }
  mountNode = document.createElement('div')
  mountNode.id = 'bulletin_dialog'
  document.body.appendChild(mountNode)
  app = createApp(bulletinDialog, {
    remove: () => { 
      app.unmount(mountNode); 
      document.body.removeChild(mountNode)
      mountNode = null
     },
    ...option
  })
  app.use(ElementPlus).mount(mountNode)
}
bulletinDialogModel.remove = ()=>{
  if(mountNode){
    app.unmount(mountNode); 
    document.body.removeChild(mountNode)
    mountNode = null
  }
}
export default bulletinDialogModel
